<template>
	<view>
		<cu-custom :bgColor="'bg-'+color" :isBack="true"><block slot="backText">返回</block><block slot="content"> 设计</block></cu-custom>
		<view class="cu-form-group margin-top" @tap="showModal" data-target="ColorModal">
			<view class="title">主题颜色</view>
			<view class="padding solid radius shadow-blur" :class="'bg-'+color"></view>
		</view>
		<view class="cu-form-group margin-top" @tap="showModal" data-target="BtnColorModal">
			<view class="title">按钮颜色</view>
			<view class="padding solid radius shadow-blur" :style="{'backgroundColor':btnColor}"></view>
		</view>
		<view class="cu-modal" :class="modalName=='ColorModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar justify-end solid-bottom">
					<view class="content">选择颜色</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="grid col-5 padding">
					<view class="padding-xs" v-for="(item,index) in ColorList" :key="index" @tap="SetColor" :data-color="item.name" v-if="item.name!='white'">
						<view class="padding-tb radius" :class="'bg-' + item.name"> {{item.title}} </view>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalName=='BtnColorModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar justify-end solid-bottom">
					<view class="content">选择颜色</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="grid col-5 padding">
					<view class="padding-xs" v-for="(item,index) in ColorList" :key="index" @tap="SetBtnColor" :data-colorName="item.name" :data-color="item.color" v-if="item.name!='white'">
						<view class="padding-tb radius" :class="'bg-' + item.name"> {{item.title}} </view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Vue from 'vue'
	export default {
		data() {
			return {
				ColorList: this.ColorList,
				modalName: '',
				round: false,
				size: '',
				color: Vue.prototype.bgColor,
				btnColor:Vue.prototype.btnColor,
				shadow: false,
				border: false,
				bordersize: ''
			};
		},
		methods: {
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			SetRound(e) {
				this.round = e.detail.value
			},
			SetSize(e) {
				this.size = e.detail.value
			},
			SetBtnColor(e){
				this.btnColor = e.currentTarget.dataset.color;
				Vue.prototype.btnColor = this.btnColor;
				uni.setStorage({
					key:'btnColor',
					data:this.btnColor,
					success: (res) => {
						uni.showToast({
							title:'设置成功'
						})
					},
					fail: () => {
						uni.showToast({
							title:'设置失败'
						})
					}
				})
				this.modalName = null
			},
			SetColor(e) {
				this.color = e.currentTarget.dataset.color;
				Vue.prototype.bgColor = this.color;
				uni.setStorage({
					key:'bgColor',
					data:this.color,
					success: (res) => {
						uni.showToast({
							title:'设置成功'
						})
					},
					fail: () => {
						uni.showToast({
							title:'设置失败'
						})
					}
				})
				this.modalName = null
			},
			SetShadow(e) {
				this.shadow = e.detail.value
			},
			SetBorder(e) {
				this.border = e.detail.value
				if (!e.detail.value) {
					this.bordersize = false
				}
			},
			SetBorderSize(e) {
				this.bordersize = e.detail.value
			}
		}
	}
</script>

<style>
	.box {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100px;
	}
</style>
